- /* sdfacos.cpp by K.Tsuru */
- // function ID 3101 DRADIX
- /****************************************************************
- SDouble class
- arccos x
- If |x| is very close to one, the formura
- arccos x = arcsin(sqrt((1-x)*(1+x))
- is used.
- When x = 1.0 - 10^(-100), test whether a full precision can be
- obtained or not.
- ****************************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- SDouble Acos(const SDouble& x){
- if(x.Sign(3101) == 0) return MPi2();// x = 0, pi/2
- if(x.IsOne()){ // |x| = 1
- if(x.Sign() < 0) return Pi(); // x = -1
- return 0.0; // x = 1
- }
-
- SDouble r;
- bool nearlyOne = false; // 1-|x| << 1.0 ?
-
- if(x.Sign() > 0) r = ONE - x; // must be r = 1.0 - |x| >= 0
- else r = ONE + x;
-
- if(r.NetRdxExp() < -1) nearlyOne = true;// |r| < 10^(-2*DFIGURES) = 1e-8
- if(r.Sign() < 0) x.SetError(x.DOMAIN_ERR, "Acos",3101); // |x|>1
-
- if(nearlyOne){ // by a formula arccos x = arcsin sqrt(1-x*x)
- if(x.Sign() > 0) r *= (ONE + x);
- else r *= (ONE - x);
- SDouble x1 = Sqrt(r); // r = 1-x^2, x1 < 1e-4
- r = Asin(x1); // r > 0 and 0 < x1 << 1.0
- if(x.Sign() < 0) r = Pi() - r; // arccos x = pi - arccos(-x)
- } else r = MPi2() - Asin(x); // pi/2 - arcsin x
- return r;
- }
sdfacos.cpp : last modifiled at 2016/08/29 16:42:52(1,283 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).